*! version 3.0 13Mar2017 
*! by Hung-Jen Wang
*!    Department of Economics, National Taiwan University
*!    wangh@ntu.edu.tw

capture program drop lookado
program define lookado


   gettoken fn 0 : 0, parse(" ,")
   syntax [, File(string)]

   version 6

   hjw_ff `1'

   if "`file'" ~= ""{ /* specify a file */

     if `file' < 1 { /* insensible */
       di in red "Wrong file number specification; the number must be >= 1."
       exit 199
      }
     if `file' > $ifn { /* out of range */
      di in red "There are only $ifn related files, and you asked for the `file'th."
      exit 199
      }
   }


   if $ifn == 1 { /* open the only file */
        capture winexec d:\editors\winedt32\ProEdt.exe -C=ProEdt "$fn1"
        if _rc ~= 0 {
          winexec notepad "$fn1"
        }
   }

   if ($ifn > 1) & ("`file'" ~= "") { /*  more than one files; open a specific one */

        capture winexec d:\editors\winedt32\ProEdt.exe -C=ProEdt "${fn`file'}"
        if _rc ~= 0 {
           winexec notepad "${fn`file'}"
        }
   }


   if ($ifn > 1) & ("`file'" == "") { /* more than one files; don't know which one to open */
      di in yel "There are more than one files with the name `1'."

      local i = 1
      while `i' <= $ifn {
         di in gre "  The `i'st:  " "${fn`i'}"
         local i = `i' + 1
      }

      di in yel "Type "
      di in gre "    lookado `1', f(" in yel "#" in gre")"
      di in yel "to open the #th file listed above."
   }




end
